package models

import (
	"context"
	"database/sql"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

func (m *defaultMessageModel) SessionInsert(ctx context.Context, session *sqlx.Session, data *Message) (sql.Result, error) {
	messageIdKey := fmt.Sprintf("%s%v", cacheMessageIdPrefix, data.Id)
	ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
		query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, messageRowsExpectAutoSet)
		return conn.ExecCtx(ctx, query, data.SenderId, data.ReceiverType, data.ReceiverId, data.ContentType, data.Content, data.FileName, data.FileSize, data.Status)
	}, messageIdKey)
	return ret, err
}
